package com.seanchenxi.gwt.wordpress.xmlrpc.service.model.handler;

import java.util.ArrayList;
import java.util.List;

import com.seanchenxi.gwt.wordpress.domain.model.Page;
import com.seanchenxi.gwt.wordpress.xmlrpc.service.model.impl.ModelFactory;
import com.seanchenxi.gwt.xmlrpc.client.impl.BaseResponseHandler;

public class PagesResponseHandler extends BaseResponseHandler<ArrayList<Page>> {
	
	@Override
	public ArrayList<Page> handleResponse(String response) {
		Object object = super.handleResponse(response);
		
		if(ModelFactory.isNotList(object)) return null;
		
		ArrayList<Page> pages = new ArrayList<Page>();
		for(Object obj : (List<?>)object){
			Page page = ModelFactory.ToPage(obj);
			if(page!=null && !pages.contains(page)){ 
				pages.add(page);
			}
		}
			
		return pages;
	}
}
